package com.py.korona.ui.controls.activities;

import android.app.Activity;
import android.os.Bundle;
import com.py.korona.R;

public abstract class CustomActivity extends Activity {
    protected enum CustomActivityDetailState {
        CustomActivityDetailStateEdit, CustomActivityDetailStateView
    }
    private CustomActivityDetailState detailState;
    private boolean                   hasModified;

    public boolean isHasModified() {
        return hasModified;
    }

    public void setHasModified(boolean hasModified) {
        this.hasModified = hasModified;
    }

    public abstract boolean isDetailStateAllowed(CustomActivityDetailState state);

    public abstract void onEnteringEditMode();

    public abstract void onEnteringViewMode();

    public CustomActivityDetailState getDetailState() {
        return detailState;
    }

    public void setDetailState(CustomActivityDetailState detailState) {
        if (this.isDetailStateAllowed(detailState)) {
            this.detailState = detailState;
            switch (detailState) {
                case CustomActivityDetailStateEdit: {
                    this.onEnteringEditMode();
                    break;
                }
                case CustomActivityDetailStateView: {
                    this.onEnteringViewMode();
                    break;
                }
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTheme(R.style.MyTheme);
        overridePendingTransition(R.anim.pull_in_from_right, R.anim.hold);
        hasModified = false;
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.hold, R.anim.pull_out_to_right);
    }
}
